#include "../../lv_examples.h"
#if LV_USE_KEYBOARD && LV_BUILD_EXAMPLES

void lv_example_keyboard_2(void)
{
    /*Create an AZERTY keyboard map*/
    // 创建一个 AZERTY 键盘映射

    // 创建键盘按键数组装填按键
    static const char * kb_map[] = {"A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", LV_SYMBOL_BACKSPACE, "\n",
                                    "Q", "S", "D", "F", "G", "J", "K", "L", "M",  LV_SYMBOL_NEW_LINE, "\n",
                                    "W", "X", "C", "V", "B", "N", ",", ".", ":", "!", "?", "\n",
                                    LV_SYMBOL_CLOSE, " ",  " ", " ", LV_SYMBOL_OK, NULL
                                   };

    /*Set the relative width of the buttons and other controls*/
    // 设置按钮和控件的相对宽度，即总宽度的比例分成,LV_BTNMATRIX_CTRL_HIDDEN | 2为该相对宽度部分进行隐藏屏蔽
    static const lv_btnmatrix_ctrl_t kb_ctrl[] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
                                                  4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
                                                  4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
                                                  2, LV_BTNMATRIX_CTRL_HIDDEN | 2, 6, LV_BTNMATRIX_CTRL_HIDDEN | 2, 2
                                                 };

    /*Create a keyboard and add the new map as USER_1 mode*/
    // 创建一个键盘，并添加新的映射为 USER_1 模式

    // 创建一个键盘
    lv_obj_t * kb = lv_keyboard_create(lv_scr_act());
    //将数组和键盘相对宽度映射添加到键盘中，并放入为 USER_1 模式
    lv_keyboard_set_map(kb, LV_KEYBOARD_MODE_USER_1, kb_map, kb_ctrl);
    //设置键盘模式为 USER_1
    lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_USER_1);

    /*Create a text area. The keyboard will write here*/
    // 创建一个文本区域。键盘将写入这里

    // 创建一个文本区域，用于写到文本框显示
    lv_obj_t * ta;
    ta = lv_textarea_create(lv_scr_act());
    //设置文本区域位置
    lv_obj_align(ta, LV_ALIGN_TOP_MID, 0, 10);
    //设置文本区域大小
    lv_obj_set_size(ta, lv_pct(90), 80);
    //设置文本区域焦点，聚焦可让选定区域设置不同的视觉表现，使得用户能够清晰地看到当前哪个对象是活跃的。
    lv_obj_add_state(ta, LV_STATE_FOCUSED);
    //设置文本区域文本与键盘绑定
    lv_keyboard_set_textarea(kb, ta);
}
#endif
